package com.cykj.faceledtv.ui.main;

import android.content.Context;

import com.cykj.faceledtv.data.DataManager;
import com.cykj.faceledtv.ui.base.BasePresenter;

import java.util.List;

import javax.inject.Inject;

import interfaces.heweather.com.interfacesmodule.bean.weather.forecast.Forecast;
import interfaces.heweather.com.interfacesmodule.bean.weather.forecast.ForecastBase;
import interfaces.heweather.com.interfacesmodule.view.HeWeather;
import io.reactivex.disposables.CompositeDisposable;

/**
 * @author jzh
 * @date 2019/05/10 14:58
 */
public class MainPresenter<v extends MainMvpView> extends BasePresenter<v> implements MainMvpView.MainMvpPresenter<v> {
    @Inject
    public MainPresenter(DataManager dataManager, CompositeDisposable compositeDisposable) {
        super(dataManager, compositeDisposable);
    }

    @Override
    public void doGetWeather(final Context context, final String city) {
        HeWeather.getWeatherForecast(context, city, new HeWeather.OnResultWeatherForecastBeanListener() {
            @Override
            public void onError(Throwable throwable) {
                doGetWeather(context, city);
            }

            @Override
            public void onSuccess(Forecast forecast) {
                if (forecast == null) {
                    return;
                }
                List<ForecastBase> data = forecast.getDaily_forecast();
                if (data == null || data.size() < 2) {
                    return;
                }
                ForecastBase base = data.get(0);
                ForecastBase base1 = data.get(1);
                if (base == null || base1 == null) {
                    return;
                }
                getMvpView().onSuccess((base.getCond_txt_d() + base.getTmp_min() + "度-" + base.getTmp_max() + "度"),
                        (base1.getCond_txt_d() + base1.getTmp_min() + "度-" + base1.getTmp_max() + "度"), base.getCond_code_d(),
                        base1.getCond_code_d());
            }
        });
    }
}
